package com.gitee.wsl.mathematics.coordinate.ext

import com.gitee.wsl.mathematics.vector.Vector
import com.gitee.wsl.mathematics.vector.ext.dot
import com.gitee.wsl.mathematics.vector.ext.norm
import com.gitee.wsl.mathematics.vector.ext.zip


/** 计算两个向量之间的某种距离 */
/*
enum class DistanceType(val between: (Vector<*, *>, Vector<*, *>) -> Double) {
    *//** 用弧度表示的夹角 *//*
    IncludedAngle({ one, other -> kotlin.math.acos(((one dot other) / one.length / other.length).toDouble()) }),

    *//** 欧式距离 *//*
    Euclid({ one, other -> (one - other).length }),

    *//** 曼哈顿距离 *//*
    Manhattan({ one, other -> (one - other).norm(+1) }),

    *//** 切比雪夫距离 *//*
    Chebyshev({ one, other -> (one - other).norm(-1) });

    infix fun between(pair: Pair<Vector, Vector>) = between(pair.first, pair.second)
}
*/

/** @return 与[other]间用弧度表示的夹角 */
infix fun<T:Number> Vector<T, *>.includedAngle(other: Vector<T, *>) = acos((this dot other) / this.length / other.length)

/** @return 与[other]间的欧式距离 */
infix fun<T:Number> Vector<T, *>.euclid(other: Vector<T, *>) = (this - other).length

/** @return 与[other]间的曼哈顿距离 */
infix fun<T:Number> Vector<T, *>.manhattan(other: Vector<T, *>) = (this - other).norm(+1)

/** @return 与[other]间的切比雪夫距离 */
infix fun<T:Number> Vector<T, *>.chebyshev(other: Vector<T, *>) = (this - other).norm(-1)

private operator fun<T:Number,V: Vector<T, V>> Vector<T, V>.minus(other: Vector<T, *>) = zip(other) { a, b -> a - b }
